<template>
	<view>
		<view class="tabs">
			<van-tabs v-model="active" sticky offset-top="30px">
				<van-tab title="所有谏言">
					<view class="" v-for="(item, index) in AdviceList" :key="index">
						<uni-card :title="item.adviceTitle" :extra="item.adviceTime"
							:thumbnail="imageList(item.advicePhoto)">
							<mp-html class="notice-content content" :content="item.adviceContent" />
							<view class="chahui">
								<text style="color: blue; margin-right: 20px;" @click="showAdvice(item)">查看</text>
								<text style="color:red ;" v-show="item.replyStatus==0" @click="noReply" >未回复</text>
								<text style="color:blue ;" v-show="item.replyStatus==1" @click="yesReply(item.replyContent)" >已回复</text>
							</view>
						</uni-card>
					</view>
				</van-tab>
				<van-tab title="我的谏言">
					<my-advice :MyAdviceList="this.MyAdviceList" ></my-advice>
				</van-tab>
				<van-tab title="我要谏言">
				  <submit-advice :userId="this.user.userId"></submit-advice>
				</van-tab>
			</van-tabs>
		</view>
	</view>
</template>

<script>
	import {
		getAllAdvice,getUser,getMyAdvice
	} from "@/api/home/home.js"
	import mpHtml from '@/components/mp-html/mp-html' 
	export default {
		data() {
			return {
				AdviceList: [],
				active: 0,
				user:{},
				MyAdviceList:[]
			};
		},
		methods: {
			submit() {
			},
			noReply(){
				this.$showTip('耐心等待回复!!')
			},
			yesReply(msg){
				uni.showModal({
				    content: msg,
					 showCancel: false,
				    success: function (res) {
				        if (res.confirm) {
				            // console.log('用户点击确定');
				        } else if (res.cancel) {
				            // console.log('用户点击取消');
				        }
				    }
				});
			},
			showAdvice(event){
				uni.navigateTo({
					url: '/pages/adviceDetails/adviceDetails?item='+encodeURIComponent(JSON.stringify(event))
				})
			}

		},
		onShow() {
			getAllAdvice().then(res => {
				if (res.code = 200) {
					this.AdviceList = res.data;
					console.log(res.data);
				}
			}),
			getUser().then(res=>{
					if(res.data.code=200){
					this.user=res.data	
				  getMyAdvice(res.data.userId).then(res=>{
						if(res.code==200){
							this.MyAdviceList=res.data
						}
					})
					}
					
				})
			
		},
		computed: {
			imageList() {
				return function(e) {
					if(e==null){
						return '@/static/images/head.jpg'
					}
					return e.split(",")[0]
				}
			},
		}
	}
</script>

<style lang="scss">
	.tabs {
		border-top: 2px solid #efefef;

	}

	.chahui {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
	}

	.content {
		overflow: hidden;
		-webkit-line-clamp: 2;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
	}

	.example {
		padding: 15px;
		background-color: #fff;
	}

	.segmented-control {
		margin-bottom: 15px;
	}

	.button-group {
		margin-top: 15px;
		display: flex;
		justify-content: space-around;
	}

	.form-item {
		display: flex;
		align-items: center;
	}

	.button {
		display: flex;
		align-items: center;
		height: 35px;
		margin-left: 10px;
	}

	.notice-content {
		display: block;
		font-family: PingFangSC-Regular;
		font-size: 14px;
		color: #482929;
		letter-spacing: 0;
		line-height: 20px;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: normal;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
		/*规定最多显示两行*/
	}
	.replyBlue{
	  color: blue;	
	}
	.replyRed{
		color: red;
	}
</style>
